package com.zhx.threadcoreknowledge.threadobjectclasscommonmethod;

import java.util.concurrent.TimeUnit;

/**
 * @author ：zhanghaixuan
 * @date ：Created in 2019-10-03 19:47
 * 用途         ： 演示join中 被中断的情况
 */
public class JoinInterrupt {

    public static void main(String[] args) {
        Thread mainThread = Thread.currentThread();
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    mainThread.interrupt();
                    TimeUnit.SECONDS.sleep(5);
                    System.out.println("子线程执行完毕");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
        System.out.println("等待子线程执行完毕");
        try {
            thread.join();
        } catch (InterruptedException e) {
            System.out.println(Thread.currentThread().getName());
            e.printStackTrace();
        }
        System.out.println("子线程已经运行完毕");
    }
}
